package com.chase.framerwork.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections.map.ListOrderedMap;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;

import com.chase.framerwork.service.CruiserService;

@ParentPackage("chase-struts")
@Namespace("/")
@Action(value = "cruiseAction", results = { @Result(name = "success", location = "/superCruiser.jsp") })
@Scope("prototype")
@SuppressWarnings("unchecked")
public class CruiserAction extends BaseAction
{

	private CruiserService cruiseService;

	private String sql;
	
	private List<Map<String, Object>> list;

	/**
     * 
     */
	private static final long serialVersionUID = 1L;

	public String DDL() throws Exception
	{
		cruiseService.DDL(sql);

		return SUCCESS;
	}

	public String DML() throws Exception
	{
		list = new ArrayList<>();
		try
		{
			list = cruiseService.DML(sql);
		}
		catch (Exception e)
		{
            Map<String, Object> map = new ListOrderedMap();

			map.put("status", "fail");
			map.put("result", e.getCause().getMessage());

			list.add(map);
		}

		return SUCCESS;
	}

	public String getSql()
	{
		return sql;
	}

	public void setSql(String sql)
	{
		this.sql = sql;
	}

	public CruiserService getCruiseService()
	{
		return cruiseService;
	}

	@Resource
	public void setCruiseService(CruiserService cruiseService)
	{
		this.cruiseService = cruiseService;
	}

	public List<Map<String, Object>> getList()
    {
    	return list;
    }

	public void setList(List<Map<String, Object>> list)
    {
    	this.list = list;
    }
}
